<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
   	protected function _initViews() {
		$this->bootstrap('view');
		$view = $this->getResource('view');
		Zend_Registry::set('view', $view);
		$view->headTitle()->setSeparator(' - ')->headTitle('Mercado Legal');
        $view->headMeta()->appendHttpEquiv('Content-type', 'text/html;charset=utf-8');
    }
    
    protected function _initTranslate()
    {
        $translate = new Zend_Translate('Array', APPLICATION_PATH . '/resources/languages/pt_BR/Zend_Validate.php');
        Zend_Validate_Abstract::setDefaultTranslator($translate);
    }        
    
    protected function _initCache()
    {
        /*$frontend = array('lifetime' => 7200, 'automatic_serialization' =>true);
        $backend = array('cache_dir' => '/tmp');
        $cache = Zend_Cache::factory('Output', 'File', $frontend, $backend);
	
        Zend_Registry::set('cache',$cache);

        $writer = new Zend_Log_Writer_Stream('/tmp/mercado_legal.log');
        $logger = new Zend_Log();
        $logger->addWriter($writer);
        Zend_Registry::set('log',$logger);*/
    }

    protected function _initSession()
    {
        Zend_Session::start();
    }
    

    protected function _initBancoDados()
    {
		if ($_SERVER['HTTP_HOST'] == 'localhost'){
			$configBanco['host'] = "localhost";
			$configBanco['dbname'] = "mnconsig";
			$configBanco['username'] = "root";
			$configBanco['password'] = "root";
		}else{
			$configBanco['host'] = "mysql.hostinger.com.br";
			$configBanco['dbname'] = "u969745528_mncng";
			$configBanco['username'] = "u969745528_mncng";
			$configBanco['password'] = "Ex98*d$26A}p";
		}
		
		$db = new Zend_Db_Adapter_Pdo_Mysql($configBanco);

		Zend_Db_Table_Abstract::setDefaultAdapter($db);
    }
    
    protected function _initHelper()
    {
        Zend_Controller_Action_HelperBroker::addPath('SIG/Controller/Helper/');
    }

    
    protected function _initAutoload()
    {
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->registerNamespace('SIG');
        $autoloader->setFallbackAutoloader(true);

        $moduleLoader = new Zend_Application_Module_Autoloader(array(
                'namespace'	=> 	'',
                'basePath'	=>	APPLICATION_PATH));

        return $moduleLoader;
    }
    
    protected function _initPerfil()
    {
    	$session = new Zend_Session_Namespace('role');

        if (is_null($session->role)){
    		$session->role = Zend_Controller_Action_HelperBroker::getStaticHelper('role')->nameToAlias('GUEST');
    	}
    }
    
   	protected function _initPlugins() {
        $bootstrap = $this->getApplication();
        if ($bootstrap instanceof Zend_Application) {
            $bootstrap = $this;
        }
        $bootstrap->bootstrap('FrontController');
        $front = $bootstrap->getResource('FrontController');

        $acl = new Acl();
        Zend_Registry::set('acl', $acl);

        $front->registerPlugin(new SIG_Plugins_Acl($acl));
    }

}

